#include "CCreditsState.h"
#include "CMainMenuState.h"
#include "CGame.h"
#include "Wrappers/CSGD_TextureManager.h"
#include "Wrappers/CSGD_DirectInput.h"
#include "CPrintBitmapToScreen.h"

CCreditsState::CCreditsState(void)
{
	m_nBackgroundImageID = -1;
	m_nBackgroundMusicID = -1;
	m_nMovementSFXID = -1;

	m_nBackgroundImageID = CSGD_TextureManager::GetInstance()->LoadTexture("Resource/Graphics/Art Assets/SGP_CSBackground.png");
}

CCreditsState::CCreditsState(const CCreditsState&)
{

}

CCreditsState& CCreditsState::operator=(const CCreditsState&)
{
	return *this;
}

CCreditsState::~CCreditsState(void)
{

}

CCreditsState* CCreditsState::GetInstance(void)
{
	static CCreditsState instance;
	return &instance;
}

void CCreditsState::Enter(void)
{
	m_fScroll = 0.0f;

	// Load assets
	m_nMovementSFXID = CSGD_FModManager::GetInstance()->LoadSound("resource/Sound/SGP_MenuSelection.wav");
}

bool CCreditsState::Input(void)
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(DIK_RETURN)|| CSGD_DirectInput::GetInstance()->JoystickButtonPressed(0))
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
	}

	return true;
}

void CCreditsState::Update(float fElapsedTime)
{
	m_fScroll += 0.02f;
}

void CCreditsState::Render(void)
{
	// Render a background image
	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImageID, 0, 0, 0.67f, 0.6f);

	// Temporary functionality display
	//CSGD_Direct3D::GetInstance()->DrawTextA("This is the credit state.", 200, 200, 255, 0, 0);

	// TODO: Add John O'Leske and Shawn Paris As producers

	CPrintBitmapFontToScreen::GetInstance()->Print("BACK", 20, 0, 1.0f, D3DCOLOR_XRGB(255,0,0));

	CPrintBitmapFontToScreen::GetInstance()->Print("PRODUCERS:", 170, int(240-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("JOHN O'LESKE", 170, int(270-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("SHAWN PARIS", 170, int(300-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));

	CPrintBitmapFontToScreen::GetInstance()->Print("CREATED BY", 170, int(390-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("SEA SHARP", 170, int(420-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));

	CPrintBitmapFontToScreen::GetInstance()->Print("PROGRAMMERS:", 170, int(510-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("SHAWN BERO", 170, int(540-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("JOSH WEINSTEIN", 170, int(570-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("JOSE RIVAS", 170, int(600-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("GRADY OATES", 170, int(630-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("MASON MILLER", 170, int(660-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));

	CPrintBitmapFontToScreen::GetInstance()->Print("ARTISTS:", 170, int(720-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("MAHER SAGRILLO", 170, int(750-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("CHRIS JAHOSKY", 170, int(780-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));

	CPrintBitmapFontToScreen::GetInstance()->Print("SPECIAL THANKS:", 170, int(870-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("SHAWN PARIS", 170, int(900-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("SEAN HATHAWAY", 170, int(930-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("ROBERT MARTINEZ", 170, int(960-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("DAVID BROWN", 170, int(990-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
	CPrintBitmapFontToScreen::GetInstance()->Print("DANELLA GEORGIEV", 170, int(1020-m_fScroll), 1.0f, D3DCOLOR_XRGB(0,255,0));
}

void CCreditsState::Exit(void)
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nBackgroundImageID);
}